home *** CD-ROM | disk | FTP | other *** search
- %
- % "coco.t" computes combinatorial coefficients
- %
- % Sample program for the T Interpreter by:
- %
- % Stephen R. Schmitt
- % 962 Depot Road
- % Boxborough, MA 01719
- %
-
- var i, selections, elements : int
- var answer : real
-
- program
-
- prompt "Number of selections? "
- get selections
- prompt "Out of how many elements? "
- get elements
-
- answer := elements
- for i := 1 ... selections - 1 do
-
- elements := elements - 1
- answer := answer * elements
-
- end for
-
- put "Nonunique combinations = ", answer
- answer := answer / factorial( selections )
- put "Unique combinations = ", answer
-
- end program
-
-
- function factorial( n : int ) : real
-
- var result : real
-
- result := 1
- loop
- exit when n <= 0
- result := result * n
- n := n - 1
- end loop
-
- return result
-
- end function